package com.example.qxfw.ybzz.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.example.qxfw.common.entity.qx.ForecastInfo;
import com.example.qxfw.common.util.DateUtil;
import com.example.qxfw.ybzz.mapper.ForecastInfoMapper;
import com.example.qxfw.ybzz.service.ForecastInfoService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

@Service
public class ForecastInfoServiceImpl implements ForecastInfoService {

    @Autowired
    private ForecastInfoMapper forecastInfoMapper;

    @Override
    public List<ForecastInfo> searchForecastInfo(String dateChar, String timeChar, String city) {
        List<ForecastInfo> forecastInfos = forecastInfoMapper.searchForecastInfo(dateChar, timeChar, city);
        return forecastInfos;
    }

    @Override
    public List<ForecastInfo> getForecastInfo(String dateChar, String timeChar, Integer nTimes, String city) {
        List<ForecastInfo> forecastInfos = forecastInfoMapper.queryForecastInfo(Timestamp.valueOf(dateChar), timeChar, nTimes, city);
        return forecastInfos;
    }

    @Override
    public List<ForecastInfo> searchForecastInfo1(String city) {
        return forecastInfoMapper.searchForecastInfo1(city);
    }

    @Override
    public String getMaxTime1(String timeChar, String city) {
        return forecastInfoMapper.selectMaxTime1(timeChar, city);
    }

    @Override
    public List<ForecastInfo> getMaxTime() {
        return forecastInfoMapper.selectMaxTime();
    }

    @Override
    public List<String> getTimeChar(String dateChar, String stationId) {
        return forecastInfoMapper.selectTimeChar(dateChar, stationId);
    }

    @Override
    public List<ForecastInfo> getList(String dateChar, String timeChar, String nTimes, String stationId) {
        return forecastInfoMapper.selectList(dateChar,timeChar,nTimes,stationId);
    }

    @Override
    public List<ForecastInfo> getList1(String time, String stationId) {
        return forecastInfoMapper.selectList1(time,stationId);
    }

    @Override
    public List<ForecastInfo> getList2(String dateChar, String timeChar, String city) {
        return forecastInfoMapper.selectList2(dateChar, timeChar, city);
    }

    @Override
    public List<String> getRain(String time1, String time2, String stationId) {
        return forecastInfoMapper.selectRain(time1, time2, stationId);
    }

    @Override
    public List<String> getTemp(String time1, String time2, String stationId) {
        return forecastInfoMapper.selectTemp(time1, time2, stationId);
    }

    @Override
    public List<String> getMaxTemp(String time, String stationId) {
        return forecastInfoMapper.selectMaxTemp(time,stationId);
    }

    @Override
    public List<String> getWindVelocity(String time1, String time2, String stationId) {
        return forecastInfoMapper.selectWindVelocity(time1, time2, stationId);
    }

    @Override
    public List<String> getMaxTemp1(String time, String stationId) {
        return forecastInfoMapper.selectMaxTemp1(time,stationId);
    }

    @Override
    public List<String> getMinTemp(String time1, String time2, String stationId) {
        return forecastInfoMapper.selectMinTemp(time1, time2, stationId);
    }

    @Override
    public String getMinTemp1(String time, String stationId) {
        return forecastInfoMapper.selectMinTemp1(time,stationId);
    }

    @Override
    public List<ForecastInfo> getMaxWind(String time, String stationId) {
        return forecastInfoMapper.selectMaxWind(time,stationId);
    }

    @Override
    public List<ForecastInfo> getSumValue(String stationId, String time) {
        return forecastInfoMapper.selectSumValue(stationId,time);
    }

    @Override
    public List<ForecastInfo> getStationInfo(String city) {
        return forecastInfoMapper.selectStationInfo(city);
    }

    @Override
    public List<ForecastInfo> listByParams(String dateChar, String timeChar, String stationId) {
        List<ForecastInfo> forecastInfos = forecastInfoMapper.selectList(Wrappers.<ForecastInfo>lambdaQuery()
                .eq(ForecastInfo::getDatechar,Timestamp.valueOf(dateChar))
                .eq(ForecastInfo::getTimechar,timeChar)
                .eq(ForecastInfo::getStationid,stationId)
                .and(w-> w
                        .eq(ForecastInfo::getNtimes,"24")
                        .or()
                        .eq(ForecastInfo::getNtimes,"48")
                        .or()
                        .eq(ForecastInfo::getNtimes,"72")));
        return forecastInfos;
    }

    @Override
    public List<ForecastInfo> newGetForecast(@Param("dateChar") String dateChar, @Param("timeChar") String timeChar,@Param("city") String city) {
        Timestamp timestamp = DateUtil.localDateTimeToTimestamp(DateUtil.stringToLocalDateTime(dateChar));
        return forecastInfoMapper.newGetForecast(timestamp, timeChar, city);
    }

}
